import java.io.IOException;
import java.util.List;

import org.itec.yeast.db.DataManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Test {
//	private static final Logger log = LoggerFactory.getLogger(Test.class);
//	private static final String QUERY_SQL_QUERY = "select * from interaction where Query_Strain = (select idSTRAIN from strain where Strain_Name = '";
//    private static final String QUERY_SQL_ARRAY = "select * from interaction where Array_Strain = (select idSTRAIN from strain where Strain_Name = '";
//    private static final String QUERY_SQL_CONDITION = "' and Marker_Type = ";
//    private static final String QUERY_SQL_END = ")";
//    private static final int MARKER_TYPE_QUERY = 0;
//    private static final int MARKER_TYPE_ARRAY = 1;
//
//    private static final String[] QUERYES = {"YML120C", "YOL012C", "YLR370C", "YCL011C", "YDR277C"};
//    private static final String[] ARRAYES = {"YPL274W", "YOR220W", "YHR129C", "YML113W", "YOR342C"};
	public static void main(String [] args){
		String sql = "SELECT g1.Standard_Gene_Name, g1.Alias, g2.Standard_Gene_Name, g2.Alias, s1.Strain_Name, s2.Strain_Name, s1.Marker_Type, i.Interaction_Score, i.P_Value FROM gene g1 LEFT JOIN (gene g2, strain s1, strain s2, interaction i) ON s1.GENE_idGENE = g1.idGENE AND i.Query_Strain = s1.idSTRAIN AND s2.idSTRAIN = i.Array_Strain AND g2.idGENE = s2.GENE_idGENE WHERE g1.Standard_Gene_Name in ('COG5', 'COG6', 'COG7') AND (i.Interaction_Score > 0.08 OR i.Interaction_Score < -0.08) AND i.P_Value < 0.05;";
//		String sql = "SELECT g1.Standard_Gene_Name, g1.Alias, g2.Standard_Gene_Name, g2.Alias, s1.Strain_Name, s2.Strain_Name, s1.Marker_Type, i.Interaction_Score, i.P_Value FROM gene g1 LEFT JOIN (gene g2, strain s1, strain s2, interaction i) ON s1.GENE_idGENE = g1.idGENE AND i.Array_Strain = s1.idSTRAIN AND s2.idSTRAIN = i.Query_Strain AND g2.idGENE = s2.GENE_idGENE WHERE g1.Standard_Gene_Name in ('COG5', 'COG6', 'COG7') AND (i.Interaction_Score > 0.08 OR i.Interaction_Score < -0.08) AND i.P_Value < 0.05;";
		Long start = System.currentTimeMillis();
		List resultList = DataManager.executeQuery(sql);
		Long end = System.currentTimeMillis();
		System.out.println("Total result count is " + resultList.size());
		System.out.println("Total time is " + (end - start) / 1000);
//		double avgQuery = 0;
//		double avgArray = 0;
//		double total = 0;
//		
//		// Test time of query by name of query
//		for (int i = 0; i < QUERYES.length; i++){
//			String sql = QUERY_SQL_QUERY + QUERYES[i] + QUERY_SQL_CONDITION + MARKER_TYPE_QUERY + QUERY_SQL_END;
//			System.out.println(sql);
//			long start = System.currentTimeMillis();
//			List resultList = DataManager.executeQuery(sql);
//			long end = System.currentTimeMillis();
//			total += (end - start);
//		}
//		avgQuery = total / QUERYES.length;
//		System.out.println(avgQuery);
//		
//		// Set total time to zero.
//		total = 0;
//		
//		// Test time of query by name of query
//		for (int i = 0; i < ARRAYES.length; i++){
//			String sql = QUERY_SQL_ARRAY + ARRAYES[i] + QUERY_SQL_CONDITION + MARKER_TYPE_ARRAY + QUERY_SQL_END;
//			System.out.println(sql);
//			long start = System.currentTimeMillis();
//			List resultList = DataManager.executeQuery(sql);
//			long end = System.currentTimeMillis();
//			total += (end - start);
//		}
//		avgArray = total / ARRAYES.length;
//		System.out.println(avgArray);
	}
}
